local piyun = fk.CreateSkill{
  name = "lingling__piyun",
  tags = { Skill.Limited },
}

Fk:loadTranslationTable{
  ["lingling__piyun"] = "辟运",
  [":lingling__piyun"] = "限定技，回合结束时，你可以令所有角色将手牌调整至其体力上限的张数。",

  ["#lingling__piyun-invoke"] = "辟运：是否令所有角色将手牌调整至体力上限？",

  ["$lingling__piyun1"] = "万锹裂地通王气，一脉长河定龙兴！",
  ["$lingling__piyun2"] = "凿得清波照龙舸，半是民骨半天河！",
}

piyun:addEffect(fk.TurnEnd, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(piyun.name) and
      player:usedSkillTimes(piyun.name, Player.HistoryGame) == 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if room:askToSkillInvoke(player, {
      skill_name = piyun.name,
      prompt = "#lingling__piyun-invoke",
    }) then
      event:setCostData(self, {tos = room:getAlivePlayers()})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead then
        local n = p:getHandcardNum() - p.maxHp
        if n > 0 then
          room:askToDiscard(p, {
            min_num = n,
            max_num = n,
            include_equip = false,
            skill_name = piyun.name,
            cancelable = false,
          })
        elseif n < 0 then
          p:drawCards(-n, piyun.name)
        end
      end
    end
  end,
})

return piyun
